package me.shingohu.man.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import javax.inject.Inject;

import me.shingohu.man.di.component.AppComponent;
import me.shingohu.man.mvp.IPresenter;
import me.shingohu.man.util.ProgressHudUtil;

/**
 * Created by hujie on 17/4/14.
 */

public abstract class BaseMVPActivity<P extends IPresenter> extends BaseActivity {

    @Inject
    protected P mPresenter;

    protected ProgressHudUtil progressHudUtil;

    protected BaseApplication mApplication;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mApplication = (BaseApplication) getApplication();
        progressHudUtil = new ProgressHudUtil(this);
        setupActivityComponent(mApplication.getAppComponent());
        onCreateInit(savedInstanceState);
    }


    protected abstract void onCreateInit(Bundle savedInstanceState);


    /**
     * 提供AppComponent(提供所有的单例对象)给子类，进行Component依赖
     * @param appComponent
     */
    protected abstract void setupActivityComponent(AppComponent appComponent);

    @Override
    protected void gc() {
        if (mPresenter != null) {
            mPresenter.onDestroy();
        }
        if (progressHudUtil != null) {
            progressHudUtil.destory();
        }
        this.mApplication = null;
        this.mPresenter = null;
        super.gc();

    }
}
